package com.activemanager.myHealthProfile;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import com.example.android.navigationdrawerexample.R;
import com.example.android.navigationdrawerexample.R.id;
import com.example.android.navigationdrawerexample.R.layout;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class Q1Activity extends FragmentActivity{

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_pageview_back);
		Intent intent = getIntent();
		int currentPos = intent.getIntExtra("pos", 0);
		ViewPager pager = (ViewPager) findViewById(R.id.viewpagerLayout);
		initPic();
        pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        pager.setCurrentItem(currentPos);
        Button back = (Button)findViewById(R.id.button1);
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}


	private void initPic() {
		// TODO Auto-generated method stub
		BitmapFactory.Options opt = new BitmapFactory.Options();
		opt.inPreferredConfig = Bitmap.Config.RGB_565;
		opt.inPurgeable = true;
		opt.inInputShareable = true;
		
		LinearLayout bgLayout = (LinearLayout) findViewById(R.id.leanerLayout);
//		InputStream is = getResources().openRawResource(
//				R.drawable.background_normal);
//		Bitmap bgbit = BitmapFactory.decodeStream(is, null, opt);
//		bgLayout.setBackgroundDrawable(new BitmapDrawable(bgbit));
		bgLayout.setBackgroundResource(R.drawable.bg_540);
	}


	private class MyPagerAdapter extends FragmentPagerAdapter {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int pos) {
            switch(pos%5) {

            case 0: return FirstFragment.newInstance("FirstFragment, Instance 1");
            case 1: return SecondFragment.newInstance("SecondFragment, Instance 2");
            case 2: return ThirdFragment.newInstance("ThirdFragment, Instance 3");
            case 3: return ForthFragment.newInstance("ForthFragment, Instance 4");
            case 4: return FifthFragment.newInstance("FifthFragment, Instance 5");
            default: return FirstFragment.newInstance("FirstFragment, Default");
            }
        }

        @Override
        public int getCount() {
            return Integer.MAX_VALUE;
        }       
    }
}
